package util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

/**
 * @author suwy
 * 2013-1-6
 * TODO to count the data from 2007 excel
 */
public class ReadExl4POI {

	private void readExl(String exlFilePath) {
		try {
			InputStream is = new FileInputStream(new File(exlFilePath));
			Workbook workbook = WorkbookFactory.create(is);
			Sheet sheet = workbook.getSheetAt(0);
			Row row;
			int count = 0;
			if(null != sheet) {
				for(int i = 1; i <= sheet.getLastRowNum(); i++) {
					row = sheet.getRow(i);
					for(int j = 10; j <= 33; j++) {
						if(row.getCell(j).getNumericCellValue() != 0) {
							++count;
						}
					}
					System.out.println(count);
					count = 0;
				}
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (InvalidFormatException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		ReadExl4POI instance = new ReadExl4POI();
		instance.readExl("E:/read/样本医院采购情况需求2.xlsx");
	}
}
